package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CompanyType;
import com.ruoyi.system.service.ICompanyTypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公司类型Controller
 * 
 * @author ruoyi
 * @date 2024-06-13
 */
@Controller
@RequestMapping("/system/type")
public class CompanyTypeController extends BaseController
{
    private String prefix = "system/type";

    @Autowired
    private ICompanyTypeService companyTypeService;

    @RequiresPermissions("system:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询公司类型列表
     */
    @RequiresPermissions("system:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CompanyType companyType)
    {
        startPage();
        List<CompanyType> list = companyTypeService.selectCompanyTypeList(companyType);
        return getDataTable(list);
    }

    /**
     * 导出公司类型列表
     */
    @RequiresPermissions("system:type:export")
    @Log(title = "公司类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CompanyType companyType)
    {
        List<CompanyType> list = companyTypeService.selectCompanyTypeList(companyType);
        ExcelUtil<CompanyType> util = new ExcelUtil<CompanyType>(CompanyType.class);
        return util.exportExcel(list, "公司类型数据");
    }

    /**
     * 新增公司类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公司类型
     */
    @RequiresPermissions("system:type:add")
    @Log(title = "公司类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CompanyType companyType)
    {
        return toAjax(companyTypeService.insertCompanyType(companyType));
    }

    /**
     * 修改公司类型
     */
    @RequiresPermissions("system:type:edit")
    @GetMapping("/edit/{cptId}")
    public String edit(@PathVariable("cptId") Long cptId, ModelMap mmap)
    {
        CompanyType companyType = companyTypeService.selectCompanyTypeByCptId(cptId);
        mmap.put("companyType", companyType);
        return prefix + "/edit";
    }

    /**
     * 修改保存公司类型
     */
    @RequiresPermissions("system:type:edit")
    @Log(title = "公司类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CompanyType companyType)
    {
        return toAjax(companyTypeService.updateCompanyType(companyType));
    }

    /**
     * 删除公司类型
     */
    @RequiresPermissions("system:type:remove")
    @Log(title = "公司类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(companyTypeService.deleteCompanyTypeByCptIds(ids));
    }
}
